package com.glebusheg.client 
{
	import flash.display.Sprite;

	/**
	 * @author eliasku
	 */
	public class RunMode 
	{
		public static const LOCAL:String = "local";
		public static const TEST:String = "test";
		public static const PUBLIC:String = "public";
		
		private static var _current:String = PUBLIC;
		
		public static function d(p:Sprite):void
		{
			var fv:Object = p.stage.loaderInfo.parameters;
			
			if(fv.hasOwnProperty("client_run_mode"))
			{
				_current = fv.client_run_mode;
			}
			else
			{
				if(cd(p, null)) _current = LOCAL;
				else if(cd(p, "magicfarm.selfip.info")) _current = TEST;
				else if(cd(p, "magicfarm.derkeg.com")) _current = PUBLIC;
				else if(cd(p, "ferma.derkeg.ru")) _current = TEST;
			}
		}
		
		static public function get current():String
		{
			return _current;
		}
	}
}

import flash.display.Sprite;
internal function cd(s:Sprite, d:String):Boolean
{
	var url:String = s.loaderInfo.url;
	var urlStart:int = url.indexOf("://")+3;
	var urlEnd:int = url.lastIndexOf("/");
	var domain:String = url.substring(urlStart, urlEnd);
	
	if(d) return domain.indexOf(d)>=0;

	return (url.substr(0, 4)=="file");
}